﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC_Uthorization.Domain;
using RBAC_Uthorization.Domain.Entity;
using RBAC_Uthorization.Read.API.Application.Command.SysCommand;
using RBAC_Uthorization.Read.API.DTO;

namespace RBAC_Uthorization.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiController]
    public class SysController : ControllerBase
    {
        private readonly IMediator _mediator;
        private readonly ILogger<SysController> _logger;

        public SysController(IMediator mediator, ILogger<SysController> logger)
        {
            _mediator = mediator;
            _logger = logger;
        }
        /// <summary>
        /// 系统列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<sys_System>>> GetSysList()
        {
            try
            {
                return await _mediator.Send(new SysShowCommand() { });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "获取系统列表时发生错误");
                return new ApiResult<List<sys_System>>() { Code = ResultCode.Forbidden, Message = "获取系统列表时发生错误" };
            }
        }
    }
}
